$("#toField").keyup(function(){
	var availableTags = [
		<?php
			$userQuery = mysqli_query($db, "SELECT username, firstname, lastname FROM users");
			$first = true;
			while($user = $userQuery->fetch_assoc()) {
				if(!$first)
					echo ",";
				$first = false;
				echo "\"{$user["username"]} ({$user["firstname"]} {$user["lastname"]})\"";
			}
		?>
    ];
	
    $("#toField").autocomplete({
      source: availableTags
    });
});

$('form.mail').submit(function (e) {
	e.preventDefault();
	var form = this;
	var url = "submit=get";
	url += "&to="+form["to"].value;
	url += "&title="+form["title"].value;
	url += "&message="+form["message"].value;
	setTimeout(function(){ 	
		var page = getPage(_SESSION["currentPage"], "POST", url);
		var tmpDiv = document.createElement("div");
		tmpDiv.innerHTML = page;
		document.getElementById("result").innerHTML = tmpDiv.querySelector("[id=result]").innerHTML;
	}, 1);
	
	return false;

});